<%@page import="multiface.awwadco.jpa.News"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="multiface.awwadco.jpa.PersistenceManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="java.util.Iterator"%>
<%@page import="multiface.web.util.categories.AlberoCategorieRicambi"%>
<%@page import="multiface.awwadco.jpa.Categoria"%>
<%@page import="java.util.List"%>
<%
    AlberoCategorieRicambi tree = new AlberoCategorieRicambi();
    if (session.getAttribute("albero_categorie_ricambi") == null) {
        tree.caricaDaDB();
        session.setAttribute("albero_categorie_ricambi", tree);
    } else {
        tree = (AlberoCategorieRicambi) session.getAttribute("albero_categorie_ricambi");
    }
%>
<div class="box">
    <div class="title">Part Categories</div>
    <ul class="tree">
        <%

            EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
            EntityManager em = emf.createEntityManager();
            List<News> list = em.createNativeQuery("SELECT * FROM news GROUP BY YEAR(dataora), MONTH(dataora) ORDER BY dataora DESC", News.class).getResultList();

            for (News n : list) {
                em.refresh(n);
                out.println("<li id=\"li_" + 1 + "\"><a href=\"javascript:open('news_month.jsp',{year:" +(n.getDataora().getYear()+1900)+",month:"+(n.getDataora().getMonth()+1)+"});\">News of " + multiface.web.util.Util.FormatData(n.getDataora(), "yyyy/MM") + "</a></li>");
            }
            em.close();
        %>
    </ul>
</div>
    
    